﻿using System;
using System.Collections.Generic;
using HAVNet.Core.String;


namespace HAVNet.Intros.AST
{
    public enum FormalParamModif
    {
        _,
        THIS,
        REF,
        OUT,
        PARAMS,
        ARGLIST,
    }

    public class ASTFormalParam : ASTNode
    {
        public FormalParamModif modif   { get; set; }
        public ASTType          type    { get; set; }
        public string           ident   { get; set; }

        protected ASTAttributeGroups _attrGroups = null;

        public ASTAttributeGroups attrGroups
        {
            get
            {
                if (null == _attrGroups)
                    _attrGroups = new ASTAttributeGroups();

                return _attrGroups;
            }
        }

        public ASTFormalParam ()
            : this (FormalParamModif._, null, null)
        { }

        public ASTFormalParam (ASTType type, string ident)
            : this (FormalParamModif._, type, ident)
        { }

        public ASTFormalParam (FormalParamModif modif, ASTType type, string ident)
        {
            this.modif  = modif;
            this.type   = type;
            this.ident  = ident;
        }

        public override string ToString ()
        {
            string sAttrs = ((null == _attrGroups) ? "" : _attrGroups.ToString() + " ");

            if (modif == FormalParamModif.ARGLIST)
                return sAttrs + "__arglist";
            else if (modif == FormalParamModif._)
                return sAttrs + string.Format ("{0} {1}", type, ident);
            else
                return sAttrs + string.Format ("{0} {1} {2}", modif.ToString().ToLower(),  type, ident);
        }
    }

    public class ASTFormalParamList : List<ASTFormalParam>
    {
        public override string ToString()
        {
            return Strings.joinobjs(", ", this);
        }
    }
}

